<?php
/**
 * 售后订单原路返回
 * RefundServices
 * @author renjianhong
 * @date 2021-08-06 11:58
 */


namespace Modules\Order\Services\Admin;

use Modules\Order\Entities\Order;
use Modules\Order\Repositories\Admin\RefundInterface;
use Illuminate\Http\Request;
use Modules\Order\Entities\User;

class RefundServices implements RefundInterface
{
    /**
     * 退款--原路返回
     */
    public function refundReturn($data,$order_refund)
    {

    }

    /**
     * 退回余额
     */
    public function refundBalance($data,$order_refund)
    {
        $user = User::where('id',$order_refund->user_id)->first();
        $user->money += $data['refund_price'];
        if($user->save()){
            $order_refund->refund_status = 1;
            $order_refund->refund_price = $data['refund_price'];
            $order_refund->response_time = date('Y-m-d H:i:s');
            $order_refund->refund_pay_type = $data['refund_pay_type'];
            $order_refund->save();

            $order = Order::where('id',$order_refund->order_id)->first();
            $order->order_status = 8;//已退款
            $order->save();
            return true;
        }else{
            throw new \Exception('操作退款失败');
        }
    }

    /**
     * 线下转款
     */
    public function refundOffline($data,$order_refund)
    {
        $order_refund->refund_status = 1;
        $order_refund->refund_pay_type = $data['refund_pay_type'];
        $order_refund->response_time = date('Y-m-d H:i:s');
        if($order_refund->save()){
            return true;
        }else{
            throw new \Exception('操作线下转款失败');
        }
    }

}